/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package weka.attributeSelection.semiAS.semiClusterAS;

import weka.core.Instances;

/**
 *
 * @author Administrator
 */
public class ReliefFLabledDistEval extends LabeledDistEval {

    private final Instances[] m_data;

    public ReliefFLabledDistEval(final Instances data, final Instances[] classData) {
        super(data);
        m_data = classData;
    }

    public double getDistance(int i, int j) {
        double r = 0.0;

        for (int x = 0; x < m_numClasses; x++) {
            r = r + Math.abs(Correlate.correlate(i, j, m_data[x])) / m_numClasses;
        }

        r = Math.abs(r);

//        if (r > 1 || r < 0 || r == Double.NaN) {
//                System.out.println("r=" + r);
//            }

        if (r > 1) {
            r = 1;
        }
        if (r < 0) {
            r = 0;
        }
        return 1 - r;
    }
}
